package main

import "fmt"

type ITask interface {
	Run()
}

type Task struct {
	Name string
}

func (t *Task) Run() {
	fmt.Println(t.Name)
}

type IGoPool interface {
	ExecuteTask()
	SubmitTask(task []ITask)
	ClosePool()
}

type GoPool struct {
	count int        // 协程数量
	task  chan ITask // 协程池任务
}

func (p *GoPool) ExecuteTask() {
	for i := 0; i < p.count; i++ {
		go func() {
			for t := range p.task {
				t.Run()
			}
		}()
	}
}

func (p *GoPool) SubmitTask(task []ITask) {
	for _, t := range task {
		p.task <- t
	}
}

func (p *GoPool) ClosePool() {
	close(p.task)
}
